package com.atguigu.stgy.model.result;

import lombok.Data;

@Data
public class R<T> {
    private Integer code;
    private String message;
    private T data;
    private Boolean ok;

    private static<T> R<T> build(Integer code , String message , Boolean ok , T data){
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(data);
        r.setOk(ok);
        return r;
    }

    public static <T> R<T> ok(){
        return build(200 , "SUCCESS" , true , null);
    }
    public static <T> R<T> ok(T data){
        return build(200 , "SUCCESS" , true , data);
    }
    public static <T> R<T> fail(){
        return build(201 , "ERROR" , false , null);
    }
    public static <T> R<T> fail(ResultCodeEnum codeEnum){
        return build(codeEnum.getCode() , codeEnum.getMessage(), false , null);
    }
    public static <T> R<T> fail(Integer code , String message){
        return build(code , message , false , null);
    }
}
